// @ts-ignore
import request from './request.js'

// 创建订单
export async function createOrder(data: { productIds: number[]; numbers: number[]; addressId: number; quanId: number; isShoppingCart?: boolean }) {
  return await request.post('/order/create', data)
}

// 支付订单
export async function payOrder(orderId: number, addressId: number) {
  return await request.post(`/order/pay/${orderId}`, { addressId })
}

// 获取订单统计信息
export async function getOrderStatistics() {
  return await request.get('/order/statistics')
}

// 获取我的订单
export async function getMyOrders() {
  const res = await request.get('/order/my')
  let orders = []
  if (res.data && Array.isArray(res.data.ordersPageVo)) {
    orders = res.data.ordersPageVo
  }
  return {
    ...res,
    data: orders
  }
}

// 分页获取我的订单
export async function getMyOrdersPaged(pageNo: number, pageSize: number) {
  return await request.get('/order/my', { params: { pageNo, pageSize } })
}

// 查询订单详情（支付页用）
export async function getOrderDetailForPay(orderId: number|string) {
  return await request.get(`/order/pay/query/${orderId}`)
}

// 余额支付订单（支付页用）
export async function payOrderByBalance(orderId: number|string) {
  return await request.post(`/order/pay/${orderId}`)
}
